package com.tianqu.tms.www.api.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.webservice.TmsCarGateService;
import com.tianqu.tms.www.api.form.InputParam;

public class TmsChargeSignAction extends TmsAjaxAction {
	private static  TmsCarGateService carGateService = new TmsCarGateService();
	private Logger LOGGER = Logger.getLogger(TmsChargeSignAction.class);
	private final static String CHARGE_FLAG = "1";
	@Override
	public void process(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response, UserContext uc) throws TmsException {
		String r = CHARGE_FLAG;
		try {
			String plateNum = request.getParameter("plateNum");
			String rfidInfo = request.getParameter("rfid");
			if(StringUtils.isNotBlank(plateNum)) plateNum = new String(plateNum.getBytes("iso-8859-1"),"utf-8");
			if(StringUtils.isNotBlank(rfidInfo)) rfidInfo = new String(rfidInfo.getBytes("iso-8859-1"),"utf-8");
			//
			if(StringUtils.isBlank(plateNum) && StringUtils.isBlank(rfidInfo)) {
				LOGGER.error("TmsChargeSignAction param error, param is null!");
				responseValues(response, CHARGE_FLAG, TEXT);
				return;
			}
			//
			InputParam parma = new InputParam();
			parma.setRfid(rfidInfo);
			parma.setPlateNum(plateNum);
			r = carGateService.getChargePermission(parma);
			LOGGER.info("request chargeSign api,plateNum:"+plateNum +" rfidInfo:"+rfidInfo +" result:"+ r);
		} catch (Exception e) {
			LOGGER.error("TmsChargeSignAction error.",e);
			responseValues(response, CHARGE_FLAG, TEXT);
			return;
		}
		return;
	}
}
